package com.tonglin.springboot.controller;

import com.tonglin.springboot.po.Status01;
import com.tonglin.springboot.service.LogonService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 1.接受用户提交的id，用户名，用户密码
 * 2.响应对应的页面
 *   1.如果注册成功，则返回注册成功信息
 *   2.如果注册失败，则返回注册失败信息
 *
 *
 *
 *
 */

@Controller
public class LogonController {

     @Autowired
     private LogonService logonService;

    @RequestMapping("logon")
    public String logon(String userId, String userName, String passWord, Model model){

        if(StringUtils.isBlank(userId)){

            model.addAttribute("msg01","用户id不能为空！");
            return "logon";
        }
//        if(userId instanceof String){
//            model.addAttribute("msg01","请输入整型id");
//            return "logon";
//        }
        Integer userID = Integer.parseInt(userId);
        Status01 status01 = logonService.logon(userName, passWord,userID);

        if(status01.isCode()){
            model.addAttribute("mm01",status01);
            model.addAttribute("name",userName);
            return "msg01";
        }else {
                    model.addAttribute("msg01",status01.getMsg());


            return "logon";

        }
}

    @RequestMapping("showtitle")
    public String gotoIndex(){

        return  "logon";
    }

    @RequestMapping("showtitle01")
    public String gotoIndex01(){


        return "update";
    }

}
